﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.LambWeaningCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Dto.InputDto;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.LambWeaningHandler
{
    public class LambWeaningSelectHandler:IRequestHandler<LambWeaningSelectCommand,Results<List<LambWeaning>>>
    {
        private readonly ILambWeaningService _lambService;
        private readonly IMapper _mapper;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="lambService"></param>
        /// <param name="mapper"></param>
        public LambWeaningSelectHandler(ILambWeaningService lambService, IMapper mapper)
        {
            _lambService = lambService;
            _mapper = mapper;
        }


        /// <summary>
        /// 羔羊断奶列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<List<LambWeaning>>> Handle(LambWeaningSelectCommand request, CancellationToken cancellationToken)
        {
            var lambList = _mapper.Map<LambWeaningInput>(request);
            var list = _mapper.Map<List<LambWeaning>>(await _lambService.GetLambWeaning(lambList));

            return Results<List<LambWeaning>>.DataResult(list);

        }
    }
}
